package com.one.enums;

import com.one.dto.EnumResult;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public enum RoleEnum {
    TEACHER("2","教师"),STUDENT("3","学生");

    private String key;
    private String value;
    RoleEnum(String key, String value) {
        this.key = key;
        this.value = value;
    }
    public static String getEnumValue(String key) {
        RoleEnum[] roleEnums = RoleEnum.values();
        for (RoleEnum roleEnum : roleEnums) {
            if (roleEnum.getKey().equals(key)) {
                return roleEnum.getValue();
            }
        }
        return null;
    }
    public static List<EnumResult> getEnumList() {
        RoleEnum[] roleEnums = RoleEnum.values();
        List<EnumResult> result = Stream.of(roleEnums).map(
                entry -> new EnumResult(entry.getKey(), entry.getValue())).collect(Collectors.toList());
        return result;
    }
    public String getKey() {
        return key;
    }

    public String getValue() {
        return value;
    }
}
